package com.sky.wsp.camel;

import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;

import java.util.List;

/**
 * @desccription 针对JavaBean属性、getr/set方法，实现snake风格转换为camel风格
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2022/12/20
 */
public class FileSplitUtils02 {

    private static String sourcePath = "C:\\Users\\24044\\Desktop\\30\\29sql-update-inn_dps_posts.sql";
    private static String targetPath = "C:\\Users\\24044\\Desktop\\30\\29sql-update-inn_dps_posts2222222.sql";
    //    private static String sourcePath = "C:\\Users\\24044\\Desktop\\111.sql";
//    private static String targetPath = "C:\\Users\\24044\\Desktop\\222.sql";
    private static Integer count = 0;

    public static void main(String[] args) {
        System.out.println("开始处理...");
        StringBuilder sb = new StringBuilder();
        FileReader fileReader = new FileReader(sourcePath);
        List<String> lines = fileReader.readLines();
        if (lines.isEmpty()) {
            return;
        }
        for (String l : lines) {
            count++;
            String[] split = l.split(" WHERE ");

            if (split.length != 2) {
                System.out.println(count + " 跳过: " + l);
                continue;
            } else {
//                System.out.println(count);
            }
//            String[] split2 = split[1].split("`approvals`=");
            String[] split2 = split[1].split("`id`=");
            String nextStr = split2[1];
            String id = nextStr.split(" ")[0];
            sb.append(split[0]).append(" WHERE id = '").append(id).append("';\r\n");
        }
        FileWriter writer = new FileWriter(targetPath);
        writer.write(sb.toString());
        System.out.println("================总共处理" + "【" + count + "】行SQL!!!=======================");
    }
}
